package gamefw.gameplugin;

import gamefw.framework.Coordinate;
import gamefw.uiplugin.IVisualResource;

/**
 * This class holds the logical representation of a game board.
 * The implementation should hold the list of GameEntities in the board and also
 * the visual representation of the board done through a concrete implementation of
 * the VisualBoard abstract class.
 */
public abstract class GameBoard implements IVisualResourceProvider {
	
	private IVisualResource visualResource;

	/**
	 * Initializes the game board. This method should initialize the internal 
	 * structures that represent the board and also all the pieces that are included
	 * in the initial setup of the board (each piece should be a GameEntity)
	 */
	public abstract void initGameBoard(GameEntity[] entities);
	
	/**
	 * Gets the number of rows
	 * 
	 * @return the number of rows
	 */
	public abstract int getRowsCount();
	
	/**
	 * Gets the number of columns
	 * 
	 * @return the number of columns
	 */
	public abstract int getColsCount();
	
	/**
	 * Gets the entity for a given logical position.
	 *
	 * @param position the logical position
	 * @return the GameEntity that represents the entity or null if there is no piece in the given coordinate
	 */
	public abstract GameEntity getEntity(Coordinate position);
	
	/**
	 * Sets the entity to the given position.
	 * 
	 * @param position the logical position
	 * @param entity the GameEntity object
	 */
	public abstract void setEntity(Coordinate position, GameEntity entity);
	
	/**
	 * Gets the empty positions on the board
	 * @return the array of the empty positions
	 */
	public abstract Coordinate[] getEmptyPositions();
	
	/**
	 * Gets all the entities on the board
	 * @return the array of all the entities
	 */
	public abstract GameEntity[] getEntities();

	/**
	 * Displays the board. This method should call the draw method of its visual board 
	 * and also all the display methods of each GameEntity (consequently, each GameEntity wil
	 * will call the draw method on its VisualEntity concrete implementation).
	 */
	public abstract void display();

	/**
	 * Get the visual board
	 * @return associated VisualBoard object
	 */
	public IVisualResource getVisualResource() {
		return visualResource;
	}

	/**
	 * Set the visual board. Called by GameManager.
	 * @param visualResource VisualBoard object
	 */
	public void setVisualResource(IVisualResource visualResource) {
		this.visualResource = visualResource;
	}
	
	/**
	 * Gets the logical position given a physical position.
	 *
	 * @param physicalPosition the physical position
	 * @return the logical position
	 */
	public abstract Coordinate getLogicalPosition(Coordinate physicalPosition);
	
	/**
	 * Gets the physical position given a logical position.
	 *
	 * @param logicalPosition the logical position
	 * @return the physical position
	 */
	public abstract Coordinate getPhysicalPosition(Coordinate logicalPosition);
}
